import config from './config.js'

const request = ({name='image',file}) => {
	return new Promise((resolve,reject) => {
		uni.uploadFile({
			// #ifdef H5
			url: `${config.baseUrl}/api/oss/uploadForApp`, //仅为示例，非真实的接口地址
			// #endif
			// #ifdef APP-PLUS || MP-WEIXIN
			url: `${config.proxy}/api/oss/uploadForApp`, //仅为示例，非真实的接口地址
			// #endif
			filePath: file,
			name,
			formData: {
				// 'token': store.getters.token
			},
			success: (res) => {
				if(res.statusCode == 200) {
					const data = JSON.parse(res.data)
					if(data.code === 0) {
						const img = data.data;
						resolve(img)
					}
				}else {
					uni.showToast({
						title: '上传失败，请重试！',
						icon: 'none'
					})
					reject(res.data)
				}
			},
			fail: err => {
				console.log(err,'err')
				uni.showToast({
					title: '上传失败，请重试！',
					icon: 'none'
				})
				reject(err)
			}
		});
	})
}
export default request